package de.gdgkarlsruhe.programminfo;

import java.lang.ref.WeakReference;
import java.util.List;

import android.app.ListFragment;
import android.os.AsyncTask;
import android.widget.Toast;

public class AsyncProgramminfoTask extends AsyncTask<Void, Void, List<Track>> {
	public ProgramminfoRequest mRequest;
	public WeakReference<ListFragment> mCtxRef;
	
	
	public AsyncProgramminfoTask(ProgramminfoRequest request, ListFragment context) {
		mRequest = request;
		mCtxRef = new WeakReference<ListFragment>(context);
	}

	@Override
	protected List<Track> doInBackground(Void... arg0) {
		return mRequest.loadTrackData();
	}

	@Override
	protected void onPostExecute(List<Track> result) {
		super.onPostExecute(result);
		ListFragment ctx = mCtxRef.get();
		if (null != ctx) {
			ctx.setListAdapter(new TrackListAdapter(ctx, result));
		}
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		ListFragment ctx = mCtxRef.get();
		if (null != ctx) {
			Toast.makeText(ctx.getActivity(), "Starte Webzugriff...", Toast.LENGTH_SHORT).show();
		}
	}
	
}